<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>保险录单</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="insPlcBscInfo_form">
    <div class="fieldset1 tabel_col clearFix">
        <div class="caption">
            <span class="title">保单基本信息</span>
        </div>
        <div class="fieldBox col_33">
            <div class="label">保险种类</div>
            <div class="field">
                <input name="insTypCd" id="insTypCd" data-value="${insPlcBscInfoVO.insTypCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">购买方式</div>
            <div class="field">
                <input name="buyWayCd" id="buyWayCd" data-value="${insPlcBscInfoVO.buyWayCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保单性质</div>
            <div class="field">
                <input name="plcPropCd" id="plcPropCd" data-value="${insPlcBscInfoVO.plcPropCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保险产品类型</div>
            <div class="field">
                <input name="prdTypCd" id="prdTypCd" data-value="${insPlcBscInfoVO.prdTypCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保险公司所属省份</div>
            <div class="field">
                <input name="rgnPrCd" id="rgnPrCd" data-value="${insPlcBscInfoVO.rgnPrCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol insplc">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保险公司所属城市</div>
            <div class="field">
                <input name="rgnCyCd" id="rgnCyCd" data-value="${insPlcBscInfoVO.rgnCyCd}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol insplc">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保险公司</div>
            <div class="field">
                <input name="insCompId" id="insCompId" data-value="${insPlcBscInfoVO.insCompId}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33" id="subIdDiv">
            <div class="label">保险支公司</div>
            <div class="field">
                <input name="insCompSubId" id="insCompSubId" data-value="${insPlcBscInfoVO.insCompSubId}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_33" id="subNmDiv" style="display: none;">
            <div class="label">保险支公司</div>
            <div class="field">
                <div class="l-text" style="width: 178px;">
                    <input name="insCompSubNm" id="insCompSubNm" type="text" class="ui-textbox l-text-field"
                           value="${insPlcBscInfoVO.insCompSubNm}" validate="{required:false,maxlength:200}"
                           style="width: 174px;">
                </div>
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保单号</div>
            <div class="field">
                <input name="plcNo" id="plcNo" type="text" class="ui-textbox" value="${insPlcBscInfoVO.plcNo}"
                       validate="{required:true,maxlength:30}">
                <span class="requiredSymbol insplc">*</span>
            </div>
        </div>

        <div class="fieldBox col_33">
            <div class="label">保费总金额</div>
            <div class="field">
                <input name="plcExpCd" id="plcExpCd" value="1" style="display: none;">
                <input name="insTtlFee" id="insTtlFee" type="text" class="ui-textbox" data-tofix="2"
                       value="${insPlcBscInfoVO.insTtlFeeDb}" ligerui="width: 178"
                       validate="{required:true,number:true}">
                <span class="requiredSymbol">*</span>

            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">起保时间</div>
            <div class="field">
                <input name="plcBgTm" id="plcBgTm" type="text" class="ui-datepicker" value="${insPlcBscInfoVO.plcBgTms}"
                       validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">止保时间</div>
            <div class="field">
                <input name="plcEndTm" id="plcEndTm" type="text" class="ui-datepicker"
                       value="${insPlcBscInfoVO.plcEndTms}"
                       validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">被保险人</div>
            <div class="field">
                <input name="insPerNm" id="insPerNm" type="text" class="ui-textbox" value="${insPlcBscInfoVO.insPerNm}"
                       validate="{required:false,maxlength:50}">
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">被保险人证件号码</div>
            <div class="field">
                <input name="insPerCretNo" id="insPerCretNo" type="text" class="ui-textbox"
                       value="${insPlcBscInfoVO.insPerCretNo}" validate="{required:false,maxlength:40}">
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">第一受益人</div>
            <div class="field">
                <input name="fstPer" id="fstPer" data-value="${insPlcBscInfoVO.fstPer}" value="${insPlcBscInfoVO.fstPer}"
                       class="ui-textbox" validate="{maxlength:45}">
            </div>
        </div>

        <div class="fieldBox col_100">
            <div class="label">特别说明</div>
            <div class="field">
                <textarea name="plcRem" id="plcRem" class="ui-textarea l-textarea" cols="130" rows="3"
                          style="width: 97%;"
                          value="${insPlcBscInfoVO.plcRem}"
                          validate="{required:false,maxlength:200}">${insPlcBscInfoVO.plcRem}</textarea>
            </div>
        </div>

        <input type="hidden" id="filePath" value="insPlcInfo"/>
        <input type="text" style="display:none" id="paySchId" name="paySchId" value="${paySchId}">
        <input type="text" style="display:none" id="prjPrdDtlId" name="prjPrdDtlId" value="${prjPrdDtlId}">
        <input type="text" style="display:none" id="paySchNo" name="paySchNo" value="${paySchNo}">
        <input type="text" style="display:none" id="plcId" name="plcId" value="${plcId}">
        <input type="text" style="display:none" id="prjId" name="prjId" value="${prjId}">
        <input type="text" style="display:none" id="contNo" name="contNo" value="${contNo}">
        <input type="text" style="display:none" id="prjTypCd" name="prjTypCd" value="${prjTypCd}">
        <input type="text" style="display:none" id="bizTypCd" name="bizTypCd" value="${bizTypCd}">
        <%--<input type="text" style="display:none" id="rgnCd" name="rgnCd" value="${rgnCd}">--%>
        <input type="text" style="display:none" id="orgCd" name="orgCd" value="${orgCd}">
        <input type="text" style="display:none" id="plcSpePolCd" name="plcSpePolCd"
               value="${insPlcBscInfoVO.plcSpePolCd}">
        <input type="text" style="display:none" id="chnPol" name="chnPol" value="${insPlcBscInfoVO.chnPol}">
    </div>

    <div class="btnsBox">
        <span id="saveInsPlcBscInfo_Btn" class="sq-button sq-button-round">保存</span>
        <span id="back_Btn" class="sq-button sq-button-round">返回</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>

</form>
<script type="text/javascript" src="<%=path%>/resource/lib/plugins/ajaxfileupload.js"></script>
<script>
    var plcPrdGrid, form;
    var upload_result_params = [];
    var plcId = null, insPlcBscInfoId = null,isTrailer="";
    var prjTypCd = "${prjTypCd}";//项目类型
    var prdStsCd = "${prdStsCd}";//资产状态
    var checkPlcNoStr = '';
    var paySchNo = $("#paySchNo").val();

  //  var LSplcNo = "${LSplcNo}";//查询保单号历史数据
    $(function () {
        insPlcBscInfoId = "${insPlcBscInfoVO.id}";//主键ID
        plcId = $("#plcId").val();
        isTrailer="${isTrailer}";//挂车标示

        $("#insCompSubId").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value && value != 'init') {
                        validateInsComp(value);
                    }
                }
                ;
            },
            autocomplete: function (e) {
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });
        $("#insCompId").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value && value != 'init') {
                        setInsSubComp();
                    }
                }
                ;
            },
            autocomplete: function (e) {
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });
        $("#rgnPrCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                setCity(value);
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value) {
                        setInsSubComp();
                    }
                }
                ;
            },
            autocomplete: function (e) {
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });
        $("#rgnCyCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value) {
                        setInsSubComp();
                    }
                }
                ;
            },
            autocomplete: function (e) {
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });

        $("#plcPropCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value) {
                        changeInsSubComp();
                    }
                }
            }
        });

        /*$("#fstPer").ligerComboBox({
            data: ${fstPerTypCdList},
            valueField: 'key',
            textField: 'value'
        });*/

        $("#insTypCd").ligerComboBox({//险种
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if(value){
                    var _insTypCd = liger.get("insTypCd").getValue();
                    var _plcPropCd = liger.get("plcPropCd").getValue();
                    if(_plcPropCd&&_plcPropCd==2){//续保保单不验证是否已录入
                        return;
                    }
                    if(!insPlcBscInfoId){
                        //新增保单前验证是否已录入选中的险种
                        $.ajax({
                            type: 'get',
                            url: '<%=path%>/insurance/insPlcBscInfo/validateInsTyp.do?prjPrdDtlId=${prjPrdDtlId}&insTypCd=' + _insTypCd,
                            dataType: 'json',
                            success: function (msg) {
                                if (msg.success == 1) {
                                    if (!msg.data) {
                                        $.ligerDialog.SQalert({content: value+"已录入，如需修改请到保单管理页面操作", SQ_type: "error", SQ_showButtons: true,});
                                    }
                                } else {
                                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    }
                }
            }
        });
        $("#prdTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (this.NotFirstChange == undefined && insPlcBscInfoId) {
                    this.NotFirstChange = true;
                } else {
                    if (value) {
                    	validateInsComp(value);
                    }
                }
            }
        });
        $("#buyWayCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (value) {
                    var buyWayCd = liger.get("buyWayCd").getValue();
                    if (buyWayCd != 1) {//非我司渠道
                        changeInsSubComp();
                    } else {//我司渠
                        form.setFieldValidate("insCompSubId", {required: true});
                        form.setFieldValidate("insCompSubNm", {required: false, maxlength: 200});
                        form.setFieldValidate("plcNo", {required: true, maxlength: 30});
                        form.setFieldValidate("rgnPrCd", {required: true});
                        form.setFieldValidate("rgnCyCd", {required: true});
                        $("#subNmDiv").hide();
                        $("#subIdDiv").show();
                        $(".insplc").show();
                        setInsSubComp();
                    }
                }
            }
        });
        //起保时间change事件
        $("#plcBgTm").ligerDateEditor({
            onChangeDate: function (value) {
                var date = new Date(value);
                date.setFullYear(date.getFullYear() + 1);
                date.setDate(date.getDate() - 1);
                liger.get("plcEndTm").setValue(date);
            }
        });

        //验证保单号
         $("#plcNo").ligerTextBox({
            width: 178,
            onChangeValue: function (value) {
                validatePlcNo(value);
            }
        }); 

        form = $("#insPlcBscInfo_form").ligerForm({
            validate: true
        });
        liger.get("insTypCd").setData(${insTypCdList});
        liger.get("prdTypCd").setData(${prdTypCdList});
        liger.get("buyWayCd").setData(${buyWayCdList});
        liger.get("plcPropCd").setData(${plcPropCdList});
        liger.get("insCompId").setData(${insCompList});
        liger.get("insCompId").updateStyle();

        //显示发起流程按钮
        <c:if test="${not empty plcId}">
        <c:if test="${not empty flowFlag and flowFlag==1}">
        $('#startRenewFlow_Btn').show();
        </c:if>
        </c:if>

        //发送请求获取省级区域
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '<%=path%>/system/sysRegion/getProvinceRegion.do',
            success: function (msg) {
                if (msg.success == 1) {
                    liger.get("rgnPrCd").setData(msg.data, true);
                    liger.get("rgnPrCd").updateStyle();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

        if (insPlcBscInfoId) {//修改时禁用保险种类
            liger.get("insTypCd").setDisabled();
            $("#fileModify").show();
        }

        var typList = [];//险种列表
        <c:if test="${not empty typList}">
        typList = ${typList};
        </c:if>

        //保单产品明细
        plcPrdGrid = $("#ligergrid_insprd").ligerGrid({
            url: '<%=path%>/insurance/insPlcBscInfo/initPlcPrdList.do?prjPrdDtlId=${prjPrdDtlId}',
            method: 'get',
            columns: [
                {display: '产品名称', name: 'prdNm', minWidth: 100, align: 'center'},
                {display: '产品型号', name: 'prdMdl', width: 100, align: 'left'},
                {display: '厂商', name: 'mfrNm', minWidth: 100, align: 'left'},
                {display: '供应商', name: 'splNm', minWidth: 100, align: 'left'},
                {display: '发动机编号', name: 'engMdl', width: 100, align: 'left'},
                {display: '车架号', name: 'vinNo', width: 100, align: 'left'},
                {display: '底盘号', name: 'chsNo', width: 100, align: 'left'},
                {
                    display: '单价', name: 'prdAmt', width: 90, align: 'right',
                    render: function (rowdata, rowindex, value) {
                        return '&yen;' + FormatMoney(rowdata.prdAmt / 100);
                    }
                },
                {
                    display: '合格证号', name: 'certNo', minWidth: 100, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            return '<a href="javascript:;" onclick="detailBtn(' + rowdata.actPrdId + ',' + rowdata.prjPrdDtlId + ')">' + rowdata.certNo + '</a>';
                        }
                    }
                },
                {display: '客户名称', name: 'cstNm', width: 100, align: 'left'},
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false
        });

        //返回
        $("#back_Btn").click(function () {
            Remove_navTab();
        });

        /*保存保单*/
        $("#saveInsPlcBscInfo_Btn").click(function (event) {
            if ($("#plcNo").val()==''){
            	$("#saveInsPlcBscInfo_Btn").removeAttr("validateplcno");
			}
            var _flag = $(this).attr("validateplcno");
            if (_flag == "fail") {
                $.ligerDialog.SQalert({content: checkPlcNoStr, SQ_type: "warning", SQ_showButtons: true,});
                return false;
            }
            var data = form.getData();
            _flag = $(this).attr("validateinscomp");
            if (_flag == "fail" && data.buyWayCd == 1) {
                $.ligerDialog.SQalert({content: "保险支公司未录入返利比例", SQ_type: "warning", SQ_showButtons: true,});
                return false;
            }
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            //获取file的全部id
            var uplist = $("input[id^=addUp1]");
            var arrId = [];
            var fileNames = [];//用于判断是否有重名文件
            for (var i = 0; i < uplist.length; i++) {
                if (uplist[i].value) {
                    arrId[i] = uplist[i].id;
                    if ($.inArray(uplist[i].value, fileNames) >= 0) {
                        $.ligerDialog.SQalert({content: "上传文件(" + uplist[i].value + ")文件重名！", SQ_type: "warning"});
                        return;
                    }
                    fileNames[i] = uplist[i].value;
                }
            }

            $.ligerDialog.hide();
            var _url;
            if (!insPlcBscInfoId) {//新增
                _url = '<%=path%>/insurance/insPlcBscInfo/add.do';
                //保单产品明细TK
                var prdData = plcPrdGrid.getData();
                if(prdData.length>0){
                    data['paySchId']=prdData[0].paySchId;
                    data['paySchNo']=prdData[0].paySchNo;
                    data['prjPrdDtlId']=prdData[0].prjPrdDtlId;
                    data['prjId']=prdData[0].prjId;
                    data['cstId']=prdData[0].cstId;
                    data['cstNm']=prdData[0].cstNm;
                    data['cstMgrId']=prdData[0].cstMgrId;
                    data['cstMgrNm']=prdData[0].cstMgrNm;
                    data['buOrgCd']=prdData[0].buOrgCd;
                    data['cstMgrOrgCd']=prdData[0].cstMgrOrgCd;
                    data['contNo']=prdData[0].lsCntNo;
                }
            } else {//修改
                _url = '<%=path%>/insurance/insPlcBscInfo/modify.do?id=' + insPlcBscInfoId;
            }
            if ($("#insCompSubId").is(":hidden")) {
                data["insCompSubNm"] = $("#insCompSubNm").val();
                data["insCompSubId"] = "0";//0用来删除原来的ID
            } else {
                data["insCompSubNm"] = $("#insCompSubId").val();
            }

            //保单起始时间
            data["plcBgTm"] = $("#plcBgTm").val();
            data["plcEndTm"] = $("#plcEndTm").val();
            //保存文件及保单
            saveFileAndPlc(arrId, data, _url);
        });

        //发起续保流程
        $("#startRenewFlow_Btn").click(function (event) {
            if (!insPlcBscInfoId) {
                $.ligerDialog.SQalert({content: "请先保存保单信息", SQ_type: "warning", SQ_showButtons: true,});
                return false;
            }
            var wait_dialog;
            $.ajax({
                url: '<%=path%>/insurance/insPlcBscInfo/startRenewApply.do',
                type: 'post',
                data: {'id': insPlcBscInfoId},
                dataType: 'json',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success",SQ_showButtons:true});
                        //回调刷新列表
                        var callback = GET_W2Wcallback();
                        callback();

                        Remove_navTab();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        CreatUploadInputBox({
            target: "#addUp10_1",
            onBeforeRender: function (upfileBox) {
                upfileBox.prepend('<span class="UpfileCount">1</span>');
                upfileBox.find(".filenameBox").css("width", "150px");
            },
            placeholder: "请选择商业险电子保单",  //默认是“请选择文件”
            finishClear: true,
        });
        CreatUploadInputBox({
            target: "#addUp10_2",
            onBeforeRender: function (upfileBox) {
                upfileBox.prepend('<span class="UpfileCount">2</span>');
                upfileBox.find(".filenameBox").css("width", "150px");
            },
            placeholder: "请选择交强险电子保单",  //默认是“请选择文件”
            finishClear: true,
        });

        var FileCount = 2;
        $("#add_upfileBox").click(function (event) {
            $Html = CreatUploadInputBox({
                id: "addUp10_" + FileCount,  //id不跟着序号走！
                clearLine: true,
                deletable: true,
                finishClear: true,
                onDelete: function (upfileBox) {
                    setUpfileCount(); //删除的时候重新设置序号
                },
                onChange: function (e) {
                    $(e.target).remove_afterUploadIcon();
                }
            });
            $Html.find(".filenameBox").css("width", "150px");
            $Html.prepend('<span class="UpfileCount"></span>');
            $Html.appendTo($(this).siblings('.upfileBoxs'));
            setUpfileCount(); //新增组件后，设置序号
            FileCount++;
            SetIframe_height();
        });

    });

    function setUpfileCount() { //设置序号
        $(".UpfileCount").each(function (index, el) {
            $(this).html(index + 1);
        });
    }

    //保存文件及保单
    function saveFileAndPlc(arrId, data, _url) {
        if (arrId.length > 0) {
            var _filePath = $("#filePath").val();
            var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            $.ajaxFileUpload({
                url: '<%=path%>/system/sysulfilesrec/upload.do',
                secureuri: false,
                fileElementId: arrId,  //这里不在是以前的id了，要写成数组的形式！
                dataType: 'json',
                data: {filePath: _filePath},
                success: function (msg) {
                    if (msg.success == 1) {
                        data["fileParams"] = JSON.stringify(msg.data);
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: data,
                            url: _url,
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {
                                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                    if (!insPlcBscInfoId) {
                                        insPlcBscInfoId = msg.data;
                                    }
                                    refreshUlFileRecListByPkId(insPlcBscInfoId,"INS_PLC_BSC_INFO");
                                    $("#fileModify").show();

                                    if (plcId) {
                                        return;
                                    }
                                    //回调刷新列表
                                    var callback = GET_W2Wcallback();
                                    if(callback){
                                        callback();
                                    }

                                    Remove_navTab();
                                } else {
                                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    } else {
                        wait_dialog.close();
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                },
            });
        } else {
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if (!insPlcBscInfoId) {
                            insPlcBscInfoId = msg.data;
                        }
                        if (plcId) {
                            return;
                        }

                        //回调刷新列表
                        var callback = GET_W2Wcallback();
                        if(callback){
                            callback();
                        }

                        Remove_navTab();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
    }

    //查询城市
    function setCity(value) {
        var rgnCd = liger.get("rgnPrCd").getValue();
        if (!rgnCd) {
            return;
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {rgnCd: rgnCd},
            url: '<%=path%>/system/sysRegion/getRegionByRgnCd.do',
            success: function (msg) {
                if (msg.success == 1) {
                    liger.get("rgnCyCd").setData("", true);
                    if (msg.data) {
                        liger.get("rgnCyCd").setData(msg.data, true);
                        liger.get("rgnCyCd").updateStyle();
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //查询保险支公司
    function setInsSubComp() {
        if ($("#insCompSubId").is(":hidden")) {
            return;
        }
        var compId = liger.get("insCompId").getValue();
        if (!compId) {
            return;
        }
        var rgnPrCd = liger.get("rgnPrCd").getValue();
        if (!rgnPrCd) {
            return;
        }
        var rgnCyCd = liger.get("rgnCyCd").getValue();
        if (!rgnCyCd) {
            return;
        }
        var buyWayCd = liger.get("buyWayCd").getValue();
        if (!buyWayCd) {
            return;
        }
        var subComp = liger.get("insCompSubId");
        var paySchNo = $("#paySchNo").val();
        var prjPrdDtlId = $("#prjPrdDtlId").val();
        var plcSpePolCd = $("#plcSpePolCd").val();
        var insTypCd = liger.get("insTypCd").getValue();
        if (!insTypCd) {
            return;
        }
        var prdTypCd = liger.get("prdTypCd").getValue();
        if (!prdTypCd) {
            return;
        }
        /*if(buyWayCd!=1){
         subComp.setData([],true);
         subComp.setText("");
         return;
         }*/
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                'insCompId': compId,
                'rgnPrCd': rgnPrCd,
                'rgnCyCd': rgnCyCd,
                'buyWayCd': buyWayCd,
                'paySchNo': paySchNo,
                'prjPrdDtlId': prjPrdDtlId,
                'plcSpePolCd': plcSpePolCd,
                'insTypCd': insTypCd,
                'prdTypCd': prdTypCd
            },
            url: '<%=path%>/insurance/insCompInfo/selectInsSubComp.do',
            success: function (msg) {
                if (msg.success == 1) {
                    if (msg.data && msg.data.subCompList) {
                        subComp.setData(msg.data.subCompList, true);
                    } else {
                        subComp.setData([], true);
                        subComp.setText("");
                    }
                    if (msg.data && msg.data.chnPol) {
                        $('#chnPol').val(msg.data.chnPol);
                    }
                    subComp.updateStyle();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error", SQ_showButtons: true,});
                }
            }
        });
    }

    //格式化时间
    function renderDate(value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //验证保单号是否重复
    function validatePlcNo(_val) {    
    	var prjId = "${insPlcBscInfoVO.prjId}";
    		  if (!_val || _val=="${insPlcBscInfoVO.plcNo}") {
    	            return;
    	        }
    		  $.ajax({
                  type: 'get',
                  url: '<%=path%>/insurance/insPlcBscInfo/validatePlcNo.do',
                  data:{plcNo: _val,prdStsCd:prdStsCd},
                  dataType: 'json',
                  async:false,
                  success: function (msg) {
                      if (msg.success == 1) {
                          if (msg.data && msg.data.isSingle == 'false') {
                            if (paySchNo != msg.data.paySchNo) {
                                checkPlcNoStr = "保单号：" + _val + "与{" + msg.data.paySchNo + "}重复，请确认";
                                $.ligerDialog.SQalert({content: checkPlcNoStr, SQ_type: "warning", SQ_showButtons: true,});
                                $("#saveInsPlcBscInfo_Btn").attr("validateplcno", "fail");
                            }
                          } else {
                              $("#saveInsPlcBscInfo_Btn").removeAttr("validateplcno");
                          }
                      } else {
                          $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                      }
                  }
              }); 
    	  }
   
    //验证保险公司是否可用
    function validateInsComp(_val) {
        var _insCompId = liger.get('insCompSubId').getValue();
        if (!_insCompId) {
            return;
        }
        var buyWayCd = liger.get("buyWayCd").getValue();
        if (buyWayCd != 1) {
            return;
        }
        var _prdTypCd = liger.get('prdTypCd').getValue();
        var _prdTypCdNm = liger.get('prdTypCd').getText();
        var _insTypCd = liger.get('insTypCd').getValue();
        if (!_prdTypCd) {
            $.ligerDialog.SQalert({content: "请先选择保单产品类型", SQ_type: "warning"});
            liger.get('insCompSubId').setValue('');
            return;
        }
        $.ajax({
            type: 'get',
            url: '<%=path%>/insurance/insPlcBscInfo/validateInsComp.do?insCompId=' + _insCompId + '&prdTypCd=' + _prdTypCd + '&insTypCd=' + _insTypCd,
            dataType: 'json',
            success: function (msg) {
                if (msg.success == 1) {
                    if (msg.data && msg.data.available == 'true') {
                        $.ligerDialog.SQalert({
                            content: "此【" + _val + "】保险支公司，产品类型（" + _prdTypCdNm + "）未录入返利比例，请联系保险部！",
                            SQ_type: "warning",
                            SQ_showButtons: true,
                        });
                        $("#saveInsPlcBscInfo_Btn").attr("validateinscomp", "fail");
                    } else {
                        $("#saveInsPlcBscInfo_Btn").removeAttr("validateinscomp");
                        if (msg.data && msg.data.chnPol) {
                            $('#chnPol').val(msg.data.chnPol);
                        }
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //合格证详情
    function detailBtn(id, dtlId) {
        var detailFlag = true;
        Add_navTab('tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId);
    }
    //是否不计免赔
    function changeCheckbox(event, rowData) {
        rowData.isNonDedu = $(event.target).prop('checked');
    }
    //查询保险特殊政策，是否渠道放开
    function changeInsSubComp() {
        var buyWayCd = liger.get("buyWayCd").getValue();
        if (buyWayCd == '' || buyWayCd == 1) {
            return;
        }
        var plcTypCd = liger.get("plcPropCd").getValue();
        if (!plcTypCd) {
            return;
        }
        var insTypCd = liger.get("insTypCd").getValue();
        if (!insTypCd) {
            return;
        }
        var prjTypCd = $("#prjTypCd").val();
        var bizTypCd = $("#bizTypCd").val();
        /*var rgnCd=$("#rgnCd").val();*/
        var orgCd = $("#orgCd").val();
        $.ajax({
            type: 'post',
            url: '<%=path%>/insurance/insPlcBscInfo/getInsSubCompType.do',
            dataType: 'json',
            data: {
                'plcTypCd': plcTypCd,
                'insTypCd': insTypCd,
                'prjTypCd': prjTypCd,
                'bizTypCd': bizTypCd,
                'orgCd': orgCd
            },
            success: function (msg) {
                if (msg.success == 1) {
                    console.log("msg.succes  ===="+msg.success+"msg.data=="+msg.data);
                    if (msg.data) {
                        $("#plcSpePolCd").val(msg.data);
                        form.setFieldValidate("insCompSubId", {required: false});
                        form.setFieldValidate("insCompSubNm", {required: true, maxlength: 200});
                        form.setFieldValidate("plcNo", {required: false, maxlength: 30});
                        form.setFieldValidate("rgnPrCd", {required: false});
                        form.setFieldValidate("rgnCyCd", {required: false});
                        $("#subNmDiv").show();
                        $("#subIdDiv").hide();
                        $(".insplc").hide();
                    } else {
                        $("#plcSpePolCd").val("");
                        form.setFieldValidate("insCompSubId", {required: true});
                        form.setFieldValidate("insCompSubNm", {required: false, maxlength: 200});
                        form.setFieldValidate("plcNo", {required: true, maxlength: 30});
                        form.setFieldValidate("rgnPrCd", {required: true});
                        form.setFieldValidate("rgnCyCd", {required: true});
                        $("#subNmDiv").hide();
                        $("#subIdDiv").show();
                        $(".insplc").show();
                        setInsSubComp();
                    }
                }
            }
        });
    }

    //扩展一个 数字输入 的编辑器
    $.ligerDefaults.Grid.editors['numberbox'] = {
        create: function (container, editParm) {
            var column = editParm.column;
            var precision = column.editor.precision;
            var input = $("<input type='text' style='text-align:right;width:100%' class='l-text' />");
            input.bind('keypress', function (e) {
                var keyCode = window.event ? e.keyCode : e.which;
                return keyCode >= 48 && keyCode <= 57 || keyCode == 46 || keyCode == 8;
            });
            input.bind('blur', function () {
                var value = input.val();
                input.val(parseFloat(value).toFixed(precision));
            });
            container.append(input);
            return input;
        },
        getValue: function (input, editParm) {
            return parseFloat(input.val());
        },
        setValue: function (input, value, editParm) {
            if (!value) {
                input.val('');
                return;
            }
            var column = editParm.column;
            var precision = column.editor.precision;
            input.val(value.toFixed(precision));
        },
        resize: function (input, width, height, editParm) {
            input.width(width).height(height);
        }
    };

    //扩展 numberbox 类型的格式化函数
    $.ligerDefaults.Grid.formatters['numberbox'] = function (value, column) {
        if (!value) value = 0;
        var precision = column.editor.precision;
        return formatCurrency(value.toFixed(precision));
    };

    /**
     * 格式化金额
     */
    function formatCurrency(num) {
        if (!num) return "0.00";
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0.00";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
                num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + '' + num + '.' + cents);
    }
</script>
</body>
</html>
